﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ControlAdapter.cs" company="">
//   
// </copyright>
// <summary>
//   The control adapter.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Adapters
{
    using System;
    using System.Windows.Forms;

    using Libium.Controls;
    using Libium.Core;
    using Libium.Views;

    /// <summary>
    /// The control adapter.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public class DisabledWhenReadonlyControlAdapter<T> :ControlAdapter<T>
        where T : Control
    {
        private bool _readonly;
        private bool _enabled;

        protected DisabledWhenReadonlyControlAdapter(T control)
            :base(control)
        {
        }

        public override bool Enabled
        {
            get
            {
                return _enabled;
            }

            set
            {
                _enabled = value;
                Control.Enabled = _enabled && !_readonly;
            }
        }

        public override bool ReadOnly
        {
            get
            {
                return _readonly;
            }

            set
            {
                _readonly = value;
                Control.Enabled = _enabled && !_readonly;
            }
        }
    }
}